<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>高校宿舍管理系统-返校管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="#"/>
    <link rel="stylesheet" href="../layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../layui/css/public.css" media="all">
    <style type="text/css">
        .layui-form-item {
            display: inline-block;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 150px;">是否延迟返校</label>
                            <div class="layui-input-inline">
                                <select name="delay" id="delay" class="layui-input">
                                    <option value="2" selected>全部</option>
                                    <option value="0">是</option>
                                    <option value="1">否</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn" lay-submit lay-filter="data-search-btn">
                                <i class="layui-icon"></i>查 询
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <!-- 表格头部工具栏 -->
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button id="exportExcel" class="layui-btn layui-btn-sm data-add-btn" lay-event="export">
                    <i class="layui-icon layui-icon-file"></i>导出
                </button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <div class="layui-row layui-col-space15">
            <div class="layui-col-xs12 layui-col-md9" style="text-align: center;margin-top: 50px;">
                <div id="echarts-pies" style="background-color:#ffffff;min-height:400px;padding: 10px"></div>
            </div>
        </div>
    </div>
</div>
<script src="../layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../layui/js/lay-config.js?v=2.0.0" charset="utf-8"></script>
<script>
    layui.use(['form', 'table', 'layer', 'echarts'], function () {
        var $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            table = layui.table,
            echarts = layui.echarts;

        var tableIns = table.render({
            elem: '#currentTableId',
            url: '/teacher/back/list',
            toolbar: '#toolbarDemo',
            cols: [
                [
                    {field: 'id', title: 'ID', hide: true},
                    {field: 'stuid', width: 120, title: '学号', align: "center"},
                    {field: 'stuname', width: 120, title: '姓名', align: "center"},
                    {field: 'delay', width: 120, title: '是否延迟返校', align: "center"},
                    {field: 'reason', minWidth: 110, title: '延迟原因'},
                    {field: 'time', width: 110, title: '返校时间', align: "center"},
                    {field: 'way', width: 90, title: '返校方式'},
                    {field: 'trainnum', width: 100, title: '车次信息'},
                    {field: 'stucollege', width: 150, title: '学院', align: "center"},
                    {field: 'studept', width: 130, title: '专业', align: "center"},
                    {field: 'stuclass', width: 80, title: '班级', align: "center"},
                    {field: 'stutel', width: 120, title: '手机号', align: "center"}
                ]
            ],
            limits: [5, 10, 20, 30, 50],
            limit: 5,
            page: true,
            skin: 'line',
            even: true
        });

        $(function () {
            getPieData();
        });


        /**
         * 获取饼状图的数据
         */
        function getPieData() {
            $.ajax({
                type: "get",
                url: "/teacher/back/echartsData",
                async: true,
                dataType: "json",
                success: function (data) {
                    var delay = data.delay;
                    var notDelay = data.notDelay;
                    var echartsPies = echarts.init(document.getElementById('echarts-pies'), 'walden');
                    var optionPies = {
                        title: {
                            text: '学生返校情况',
                            x: 'center'
                        },
                        tooltip: {
                            trigger: 'item',
                            formatter: '{a} <br/>{b} : {c} ({d}%)'
                        },
                        legend: {
                            orient: 'vertical',
                            left: 'right',
                            data: ['延迟返校', '按时返校']
                        },
                        series: [
                            {
                                name: '返校情况',
                                type: 'pie',
                                radius: '60%',
                                center: ['50%', '50%'],
                                roseType: 'radius',
                                data: [
                                    {value: delay, name: '延迟返校'},
                                    {value: notDelay, name: '按时返校'}
                                ],
                                emphasis: {
                                    itemStyle: {
                                        shadowBlur: 10,
                                        shadowOffsetX: 0,
                                        shadowColor: 'rgba(0, 0, 0, 0.5)'
                                    }
                                }
                            }
                        ]
                    };
                    echartsPies.setOption(optionPies, true);
                },
                error: function () {
                    layer.msg("网络错误！", {icon: 2});
                }
            });
        }

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var type = data.field.delay;
            switch (type) {
                case "0":
                    data.field['delay'] = "是";
                    break;
                case "1":
                    data.field['delay'] = "否";
                    break;
                case "2":
                    data.field['delay'] = "";
                    break;
            }
            console.log(data.field);
            // 执行搜索重载
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //表格头部工具栏触发事件
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === "export") {
                window.location.href = "/teacher/back/export.action";
            }
            ;
        });
    });
</script>

</body>
</html>